package it.asvp.asvp_portal.asvp_util.enumerative;


public enum Role {
	
	ROLE_SOCIO("ROLE_SOCIO"),             
	ROLE_CONSIGLIERE("ROLE_CONSIGLIERE"),
	ROLE_PRESIDENTE("ROLE_PRESIDENTE"),   
	ROLE_ADMIN("ROLE_ADMIN");             
	
	private String role;
	
	Role(final String role) {
		
		this.role = role;
	}
	
	public final String getName() {
		
		return this.role;
	}
	
	public boolean equals(Role role){
		
		if(this.name().equals(role.name())){
	        return true;
		}else{
			return false;
		}
	}
	
	public static Role[] allRoles(){
		
		Role[] allRoles=new Role[4];
		allRoles[0]=ROLE_SOCIO;
		allRoles[1]=ROLE_CONSIGLIERE;
		allRoles[2]=ROLE_PRESIDENTE;
		allRoles[3]=ROLE_ADMIN;
		
		return allRoles;
	}
	
	public static Role getRoleByName(String roleName){
		
		if(ROLE_SOCIO.name().equals(roleName)){
			return ROLE_SOCIO;
		}
	    if(ROLE_CONSIGLIERE.name().equals(roleName)){
		    return ROLE_CONSIGLIERE;
	    }
	    if(ROLE_PRESIDENTE.name().equals(roleName)){
			return ROLE_PRESIDENTE;
	    }
		if(ROLE_ADMIN.name().equals(roleName)){
		    return ROLE_ADMIN;
		}   
		return null;    
	}
	
	public static Role[] subRoles(Role role){
		
		switch(role){
		
		case ROLE_SOCIO:
			Role[] subRolesSocio={ROLE_SOCIO};
			return subRolesSocio;
		case ROLE_CONSIGLIERE:
			Role[] subRolesConsigliere={ROLE_SOCIO};
			return subRolesConsigliere;
		case ROLE_PRESIDENTE:
			Role[] subRolesPresidente={ROLE_SOCIO,ROLE_CONSIGLIERE};
			return subRolesPresidente;
		case ROLE_ADMIN:
		    Role[] subRolesAdmin= {ROLE_SOCIO,ROLE_CONSIGLIERE,ROLE_PRESIDENTE,ROLE_ADMIN};
		    return subRolesAdmin;
	    default: return null;
	    
		}
	}
}
